from abc import ABC, abstractmethod

import py3func
from cui import Enum_Btn_Status

LOG = py3func.make_logging(__file__)
NONKEY_ACTIVATE_TIME = Enum_Btn_Status["released"]
Enum_Key_Type = {
    # "not_define" : 0,
    "key_char"   : 1,  # press_unicode
    "key_mode"   : 2,
    "key_func"   : 3,  # press_keycode
    "key_comb"   : 9,
}

class AbstractCmd(ABC):
    def __init__(self):
        super().__init__()
        self.name = ""


class KeyCmd(AbstractCmd):
    """ 作为按钮命令，其命令的输出存在至少两种形式，根据key-press/key-release而变更 """
    def __init__(self):
        super().__init__()

    @abstractmethod
    def key_exec(self, key_status):
        """ Acion when cmd is activated, press & release is different """
        pass


class NonKeyCmd(AbstractCmd):
    """ 作为非按钮命令，其输出只存在一种形式 """
    def __init__(self):
        super().__init__()
        # self.list_action = []  # 是否需要队列存储动作，并统一执行，由子类自行决定

    def key_exec(self, key_status):
        if key_status == NONKEY_ACTIVATE_TIME:
            self.cmd_exec()
        else:
            LOG.debug("NonKeyCmd: 延缓执行")

    @abstractmethod
    def cmd_exec(self):
        """ Acion when cmd is activated (just one time when pressing the button) """
        pass
